// 用来编写请求函数
import ajax from "./ajax"
import mockAjax from "./mockAjax"

// 获取三级导航栏数据
export function reqGetBaseCategoryList() {
  return ajax.get("/product/getBaseCategoryList")
}

// 获取轮播图数据
export function reqGetBannerListData() {
  return mockAjax.get("/banner")
}

// 获取楼层数据
export function reqGetFloorListData() {
  return mockAjax.get("/floor")
}

// 获取搜索数据
export function reqGetSearchGoodsInfoData(searchParams) {
  return ajax.post("/list", searchParams)
}
// 获取商品详情数据
export function reqGetDetailData(id) {
  return ajax.get("/item/" + id)
}

// 添加选择的商品到服务端
export function reqAddOrUpdateCart(skuId, skuNum) {
  return ajax.post(`/cart/addToCart/${skuId}/${skuNum}`)
}

// 获取购物车中的数据
export function reqGetShopCartListData() {
  return ajax.get("/cart/cartList")
}

// 更新购物车商品的状态
export function reqChangeShopCartInfoState(skuID, isChecked) {
  return ajax.get(`/cart/checkCart/${skuID}/${isChecked}`)
}
// 批量更新购物车中商品的选中状态
// export const reqChangeAllCartState = (isChecked, skuIdList) => {
//   return ajax.post(`/api/cart/batchCheckCart/${isChecked}`,skuIdList)
// }
export const reqChangeAllCartState = (isChecked, skuIdList) =>
  ajax({
    url: `/cart/batchCheckCart/${isChecked}`,
    method: "post",
    data: skuIdList,
  })

// 删除购物车中的一条商品数据
export function reqDelOneShopCartInfo(skuId) {
  return ajax.delete(`/cart/deleteCart/${skuId}`)
}
// 删除购物车中选中的商品
export function reqDelAllShopCartInfo(skuIdList) {
  return ajax.delete(`/cart/batchDeleteCart`, { data: skuIdList })
}

// 获取验证码
export function reqGetVerifyCode(phone) {
  return ajax.get(`/user/passport/sendCode/${phone}`)
}

// 注册用户
export function reqUserRegister(user) {
  return ajax.post("/user/passport/register", user)
}

// 登入
export function reqUserLogin(user) {
  return ajax.post("/user/passport/login", user)
}

// 退出
export function reqUserLogout() {
  return ajax.get("/user/passport/logout")
}

// 获取订单交易信息
export function reqGetTradeInfoData() {
  return ajax.get("/order/auth/trade")
}

// 提交订单
export function reqSubmitOrder(tradeNo, params) {
  return ajax.post(`/order/auth/submitOrder?tradeNo=${tradeNo}`, params)
}

// 获取订单支付信息
export function reqGetPaymentInfo(orderId) {
  return ajax.get(`/payment/weixin/createNative/${orderId}`)
}

// 查询支付状态
export function reqGetPayOrderState(orderId) {
  return ajax.get(`/payment/weixin/queryPayStatus/${orderId}`)
}

// 查询订单
export function reqGetOrderList(page, limit) {
  return ajax.get(`/order/auth/${page}/${limit}`)
}
